<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php
include("db.php");

function afficherNoteMoyen($id)
{
	$noteAvgSql="select avg(note) as middleNote from etudiant_note where photoid='$id'";

	$noteAvg=mysql_query($noteAvgSql);
	$result_rows=mysql_fetch_object($noteAvg);	
	
	if($result_rows != null)
	{
		echo 'Note moyen: '.number_format($result_rows->middleNote, 2);
	}
	else
	{
		echo 'Note moyen: 0';		
	}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Exam</title>
<link href="default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script language="javascript">
function afficherNote()
{
	window.open('notelist.php','newwindow','width=500,height=500');
}

function afficherNoteDetail(id)
{
	window.open('notedetail.php?id='+id,'newwindow','width=500,height=500');
}

$(document).ready( function() {
    $("#btnNote").click(function(){
        var note = $("#txtNote").val(); 
        if(note != "")
        {   
        	if(isNaN(note))
            {
        		alert("il faut remplir en chiffre !");			
    			return false;
            }         
        }
		else
		{
            alert("il faut remplir Note !");			
			return false;
        }        
    });
});
</script>
</head>
<body>

<?php
	echo "<input type='button' name=btnNoteList value='Afficher Note Liste' onClick='afficherNote();' />";
	echo "<br/>";
	echo "<br/>";
	
	$xml = simplexml_load_file("https://picasaweb.google.com/data/feed/base/user/113848708930851956597/albumid/5795380358275112865?alt=rss&kind=photo&hl=fr");
	echo "<table border='1'>";	
	foreach ($xml->channel->item as $item)
	{
		$links = explode("#", $item->link);
		if(!empty($links))
		{
			$id = $links[1];
		}
		echo '<tr><td><table>';
		echo "<tr><td>".$item->title."</td></tr>";
		echo "<tr><td><img src='".$item->enclosure['url']."' onclick='alert(this.src)' width='100' height='100'/></td></tr>";		
		echo '<form action="ecrireok.php" method="post"> ';
		echo "<tr><td><input type='text' name='txtNote' id='txtNote' />";
		echo "<input type='hidden' name=txtId value=$id />";
		echo "<input type='hidden' name=txtName value='$item->title' />";
		echo " <input type='submit' name='btnNote' id='btnNote' value='Submit' />";
		echo " <input type='button' name=btnNoteDetail value='Afficher Note' onClick='afficherNoteDetail(\"$id\");' /> ";
		echo afficherNoteMoyen($id);
		echo "</td></tr>";
		echo '</form>';
		echo "<tr><td></td></tr>";
		echo '</table></td></tr>';
	}
	echo "</table>";
?>


</body>
</html>